#include "getusersexecutor.h"

GetUsersExecutor::GetUsersExecutor(){
}

GetUsersExecutor::GetUsersExecutor(Session* s){
    session=s;
}

void GetUsersExecutor::execute(Para* cmd){
    QBool flag = QBool(false);
    foreach (Para p, cmd->getArgs())
    {
        if (p.getName() == "success")
        {
            if (p.getText() == "TRUE")
                flag=QBool(true);
            else
                flag = QBool(false);
            break;
        }
    }
    foreach (Para p, cmd->getArgs())
    {
        if (flag){
            if (p.getName() == "user")
            {
                User* usr;
                if (p.getArgs()[0].getName() == "login")
                    usr = new User(p.getArgs()[0].getText(),p.getArgs()[1].getText());
                else
                    usr = new User(p.getArgs()[1].getText(),p.getArgs()[0].getText());
                session->getCurrentRoom()->getUsers().append(usr);
            }
        }else{
            if (p.getName() == "reason")
            {
                emit fail(p.getText());
                break;
            }
        }
        emit proceed();
    }
}
